//
//  HBHShowCouponView.m
//  HubeiHotel
//
//  Created by 张露杰 on 18/4/8.
//  Copyright © 2018年 张露杰. All rights reserved.
//

#import "HBHShowCouponView.h"

@implementation HBHShowCouponView
{
    NSDictionary *_coupon;
}
- (instancetype)initWithCoupon:(NSDictionary *)coupon
{
    self = [super init];
    if (self) {
        _coupon = coupon;
        [self creatView];
    }
    return self;
}

-(void)creatView
{
    self.frame = CGRectMake(0, 0, SCREENW, SCREENH - 64);
    
    /**
     底部遮罩
     */
    UIView *backGroundView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
    backGroundView.backgroundColor = [UIColor blackColor];
    backGroundView.alpha = 0.5;
    [self addSubview:backGroundView];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismiss)];
    [backGroundView addGestureRecognizer:tap];
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 280*screenW_6, 195*screenW_6)];
    [self addSubview:view];
    UIView *couponBackView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 280*screenW_6, 195*screenW_6)];
    couponBackView.backgroundColor = TextWhite;
    couponBackView.alpha = .9;
    [view addSubview:couponBackView];
    view.center = CGPointMake(self.frame.size.width/2, self.frame.size.height/2);
    view.layer.masksToBounds = YES;
    view.layer.cornerRadius = 5*screenW_6;
    
    UILabel *titleLabel = [TomamaUI createLabel:CGRectMake(0, 29*screenW_6, view.frame.size.width, 18*screenW_6) textAligment:1 font:[UIFont systemFontOfSize:18*screenW_6] textColor:TextBlack text:@"优惠券编号"];
    [view addSubview:titleLabel];
    
    UILabel *numLabel = [TomamaUI createLabel:CGRectMake(0, CGRectGetMaxY(titleLabel.frame) + 20*screenW_6, view.frame.size.width, 18*screenW_6) textAligment:1 font:[UIFont systemFontOfSize:18*screenW_6] textColor:mainColor text:_coupon[@"number"]];
    [view addSubview:numLabel];
    
    UILabel *cueLabel = [TomamaUI createLabel:CGRectMake(0, CGRectGetMaxY(numLabel.frame) + 13*screenW_6, view.frame.size.width, 12*screenW_6) textAligment:1 font:[UIFont systemFontOfSize:12*screenW_6] textColor:[UIColor colorWithHexString:@"#666666"] text:@"请将优惠券出示给收银员进行抵扣"];
    [view addSubview:cueLabel];
    
    UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, view.frame.size.height - 50*screenW_6 - .5, view.frame.size.width, .5)];
    lineView.backgroundColor = [UIColor colorWithHexString:@"#c9c3c2"];
    [view addSubview:lineView];
    
    UIButton *btn = [TomamaUI createButton:0 Frame:CGRectMake(0, CGRectGetMaxY(lineView.frame), view.frame.size.width, 50*screenW_6) targ:self sel:@selector(dismiss) titleColor:TextBlack font:[UIFont systemFontOfSize:18*screenW_6] title:@"确定" image:nil backGroundImage:nil];
    [view addSubview:btn];
}



-(void)dismiss
{
    [UIView animateWithDuration:0.3f
                     animations:^{
                         self.alpha = 0.0;
                     }
                     completion:^(BOOL finished){
                         [self removeFromSuperview];
                     }];
}

-(void)showOnView:(UIView *)view
{
    if (!view) {
        return;
    }
    [view addSubview:self];
    [UIView animateWithDuration:0.3 animations:^{
    } completion:nil];
}


@end
